package com.zu.commu.response;

import com.zu.commu.exception.CommuException;
import com.zu.commu.interf.Action;
import com.zu.commu.interf.gprs.Response;
import com.zu.commu.remote.session.Session;
import com.zu.commu.remote.session.SessionManager;
import org.apache.log4j.Logger;

public class ResponseImp
  implements Response
{
  Logger log = Logger.getLogger("com.automic.commu.response.ResponseImp");

  public void executeAction(String gprsId, Action action, byte[] buf)
  {
    SessionManager qm = null;
    Session se;
    if (Action.SENDREMOTE.equals(action))
    {
      qm = SessionManager.instance();
      se = null;
    }try {
      se = qm.getSessionByGprsId(gprsId);
      if (se == null) {
        throw new CommuException().setMessage("对应GPRSID为" + gprsId + "GPRS还未上线", null);
      }
      se.write(buf);
    }
    catch (Exception e) {
      this.log.error(e.getMessage() + "不能完成协议要求的向远端发送数据任务！");
    }
    finally {

      if (!Action.SENDCENTER.equals(action))
      {
        if (!Action.SENDREMOTEANDCENTER.equals(action))
        {
          Action.NOACTION.equals(action);
        }
      }

    }
  }
}